package com.gdsdxy.controller;

import com.gdsdxy.dto.CommentDto;

import com.gdsdxy.dto.ResultVo;
import com.gdsdxy.mapper.CommentsMapper;
import com.gdsdxy.service.ICommentsLikeService;
import com.gdsdxy.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/comments")
@Api(tags = "评论接口")
public class CommentsController {
    @Autowired
    ICommentsService commentsService;

    @Autowired
    ICommentsLikeService commentsLikeService;

    @ApiOperation(value = "评论列表",notes = "根据博客id查询博客的相关评论")
    @GetMapping("/article/{id}")
    public ResultVo listComments(@PathVariable("id") Long id){
        return  commentsService.listComments(id);
    }

    @PostMapping("/createcomment")
    @ApiOperation(value = "评论",notes = "可进行评论和回复评论")
    public ResultVo createComment(@RequestBody CommentDto commentDto){
        return commentsService.createcomment(commentDto);
    }

    @PostMapping("/like")
    @ApiOperation(value = "评论点赞")
    public ResultVo like(@RequestParam("cid") Long cid,@RequestParam("uid") Long uid) {
        return commentsLikeService.like(cid,uid);
    }

    @DeleteMapping("/removecomment/{id}")
    @ApiOperation(value = "删除评论")
    public ResultVo remove(@PathVariable("id") Long id){
        return commentsService.removeComment(id);
    }

}
